﻿using Newtonsoft.Json;
using PC.PickleJar.Trello.Data.Resources;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace PC.PickleJar.Trello.Data
{
	internal class TrelloClient<T>
	{
		private ResourceBase<T> resource;
		private HttpClient client;

		public TrelloClient(ResourceBase<T> resource)
		{
			this.client = new HttpClient();
			this.resource = resource;
		}

		public T GetResource()
		{
			T result = default(T);

			var response = client.GetAsync(this.resource.CompleteUri).Result;
			var rawResult = response.Content.ReadAsStringAsync().Result;
			result = JsonConvert.DeserializeObject<T>(rawResult);

			return result;
		}
	}
}
